package com.atguigu.lease.web.admin.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;

public class StringToItemTypeConvertor implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
//        参数就是前端传递过来的字符串
        ItemType[] values = ItemType.values();
        if(values != null && values.length > 0){
            for (ItemType value : values) {
                if(value.getCode().equals(Integer.valueOf(source))){
                    return value;
                }
            }
        }
        return null;
    }
}